package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.entity.Provence;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/29   16:19
 * Description:ProvinceAdapter
 */

public class ProvinceAdapter extends BaseAdapter{
    private Context context;
    private List<Provence.ResultBean> datas;

    public ProvinceAdapter(Context context, List<Provence.ResultBean>  datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas!=null?datas.size():0;
    }

    @Override
    public Provence.ResultBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.view_select_provence_listview_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        Provence.ResultBean resultBean = datas.get(position);
        holder.provenceNmae.setText(resultBean.getProName());
        holder.provenceNmae.setTag(resultBean.getProID());

        return convertView;
    }
    static class ViewHolder{
        TextView provenceNmae;

        public ViewHolder(View v) {
            provenceNmae = (TextView) v.findViewById(R.id.provence_name);
        }
    }
}
